home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / boot / scsiDiskBoot / fs.h.strip < prev    next >
Encoding:
Text File  |  1989-06-10  |  15.8 KB  |  433 lines

  1. /*
  2.  * fs.h --
  3.  *
  4.  *    The external interface to the filesystem module is defined here.
  5.  *    The main object at the interface level is Fs_Stream.  A standard set
  6.  *    of operations apply to all streams.  A stream is created by
  7.  *    Fs_Open on a pathname, with flags used to differentiate between
  8.  *    the different kinds of streams.  After that, the main operations
  9.  *    are Fs_Read, Fs_Write, Fs_IOControl, Fs_Select, and Fs_Close.
  10.  *
  11.  * Copyright (C) 1987 Regents of the University of California
  12.  * All rights reserved.
  13.  * Permission to use, copy, modify, and distribute this
  14.  * software and its documentation for any purpose and without
  15.  * fee is hereby granted, provided that the above copyright
  16.  * notice appear in all copies.  The University of California
  17.  * makes no representations about the suitability of this
  18.  * software for any purpose.  It is provided "as is" without
  19.  * express or implied warranty.
  20.  *
  21.  *
  22.  * $Header: /sprite/src/kernel/fs/RCS/fs.h,v 8.10 89/06/07 16:50:26 brent Exp Locker: brent $ SPRITE (Berkeley)
  23.  */
  24.  
  25. #ifndef _FS
  26. #define _FS
  27.  
  28. #include "sys.h"
  29. #include "sync.h"
  30. #include "user/fs.h"
  31.  
  32.  
  33. /*
  34.  * The following structure is referenced by the process table entry for
  35.  * a process.  It contains all the filesystem related state for the process.
  36.  */
  37. typedef struct Fs_ProcessState {
  38.     struct Fs_Stream    *cwdPtr;    /* The current working directory. */
  39.     unsigned int       filePermissions;/* The bits in this mask correspond
  40.                      * to the permissions mask of a file.
  41.                      * If one of these bits is set it
  42.                      * TURNS OFF the corresponding
  43.                      * permission when a file is created. */
  44.     int               numStreams;    /* Size of streamList array. */
  45.     struct Fs_Stream   **streamList;    /* Array of pointers to open files.
  46.                      * This list is indexed by an integer
  47.                      * known as a streamID. */
  48.     char        *streamFlags;    /* Array of flags, one for element
  49.                      * for each open stream.  Used to
  50.                      * keep the close-on-exec property */
  51.     int            numGroupIDs;    /* The length of the groupIDs array */
  52.     int            *groupIDs;    /* An array of group IDs.  Group IDs
  53.                      * are used similarly to the User ID. */
  54. } Fs_ProcessState;
  55.  
  56.  
  57. /*
  58.  * The following low-level file system types have to be exported because
  59.  * the type of Fs_Stream is already exported.  This could be fixed by
  60.  * only exporting an opaque Fs_StreamPtr type, or by changing the definition
  61.  * of Fs_Stream from a struct to a pointer to the struct.
  62.  */
  63.  
  64. /*
  65.  * All kinds of things are referenced from the object hash table.  The generic
  66.  * term for each structure is "handle".  The following structure defines a 
  67.  * common structure needed in the beginning of each handle.  Note, most of
  68.  * these fields are private to the FsHandle* routines that do generic
  69.  * operations on handles.  One exception is that the refCount on FS_STREAM
  70.  * handles is manipulated by the stream routines.  The handle must be
  71.  * locked when examining the refCount, and it should only be changed
  72.  * under the handle monitor lock by the FsHandle* routines.
  73.  */
  74.  
  75. typedef struct FsHandleHeader {
  76.     Fs_FileID        fileID;        /* Used as the hash key. */
  77.     int            flags;        /* Defined in fsHandle.c. */
  78.     Sync_Condition    unlocked;    /* Notified when handle is unlocked. */
  79.     int            refCount;    /* Used for garbage collection. */
  80.     char        *name;        /* Used for error messages */
  81.     List_Links        lruLinks;    /* For LRU list of handles */
  82. #ifndef CLEAN
  83.     int            lockProcID;    /* Process ID of locker */
  84. #endif
  85. } FsHandleHeader;
  86.  
  87. #define LRU_LINKS_TO_HANDLE(listPtr) \
  88.     ( (FsHandleHeader *)((int)(listPtr) - sizeof(Fs_FileID) \
  89.         - 2 * sizeof(int) - sizeof(char *) - sizeof(Sync_Condition)) )
  90.  
  91. /*
  92.  * The following name-related information is referenced by each stream.
  93.  * This identifies the name of the file, which will be different than
  94.  * the file itself in the case of devices.  This is used to get to the
  95.  * name server during set/get attributes operations.  Also, this name
  96.  * fileID is used as the starting point for relative lookups.
  97.  */
  98.  
  99. typedef struct FsNameInfo {
  100.     Fs_FileID        fileID;        /* Identifies file and name server. */
  101.     Fs_FileID        rootID;        /* ID of file system root.  Passed
  102.                      * to name server to prevent ascending
  103.                      * past the root of a domain with ".."*/
  104.     int            domainType;    /* Name domain type */
  105.     struct FsPrefix    *prefixPtr;    /* Back pointer to prefix table entry.
  106.                      * This is kept for efficient handling
  107.                      * of lookup redirects. */
  108. } FsNameInfo;
  109.  
  110. /*
  111.  * Fs_Stream - A clients handle on an open file is defined by the Fs_Stream
  112.  *      structure.  A stream has a read-write offset index, state flags
  113.  *    that determine how the stream is being used (ie, for reading
  114.  *    or writing, etc.), name state used for get/set attributes,
  115.  *    and an I/O handle used for I/O operations.
  116.  *    There are many different types of I/O handles; they correspond
  117.  *    to local files, remote files, local devices, remote devices,
  118.  *    local pipes, remote pipes, locally cached named pipes,
  119.  *    remotely cached named pipes, control streams for pseudo devices,
  120.  *    psuedo streams, their corresponding server streams, etc. etc.
  121.  *    The different I/O handles types are defined in fsInt.h
  122.  *
  123.  *    This top level Fs_Stream structure is also given a handle type
  124.  *    and kept in the handle table because of process migration and
  125.  *    the shadow streams that file servers have to keep - on both
  126.  *    the client and the server there will be a Fs_Stream that
  127.  *    references an I/O handle.  The I/O handles will be different
  128.  *    types on the client (i.e. remote file) and the server (local file).
  129.  *    The Fs_Stream object will be the same, however, with the same
  130.  *    usage flags and internal ID.
  131.  *
  132.  */
  133.  
  134. typedef struct Fs_Stream {
  135.     FsHandleHeader    hdr;        /* Global stream identifier.  This
  136.                      * includes a reference count which
  137.                      * is incremented on fork/dup */
  138.     int            offset;        /* File access position */
  139.     int            flags;        /* Flags defined below */
  140.     FsHandleHeader    *ioHandlePtr;    /* Stream specific data used for I/O.
  141.                      * This really references a somewhat
  142.                      * larger object, see fsInt.h */
  143.     FsNameInfo         *nameInfoPtr;    /* Used to contact the name server */
  144.     List_Links        clientList;    /* Needed for recovery and sharing
  145.                      * detection */
  146. } Fs_Stream;
  147.  
  148. /*
  149.  * Flags in Fs_Stream that are only set/used by the kernel.
  150.  * (Flags passed in from callers of Fs_Open are defined in user/fs.h
  151.  *  The low order 12 bits of the flags word are reserved for those flags.)
  152.  * There are two groups of flags, the first is used mainly at lookup time
  153.  *    and the rest apply to I/O operations.
  154.  *
  155.  *    (These open related bit values are defined in user/fs.h)
  156.  *    FS_CREATE - Create if it doesn't exist.
  157.  *    FS_TRUNC  - Truncate to zero length on opening
  158.  *    FS_EXCULSIVE - With FS_CREATE causes open to fail if the file exists.
  159.  *    FS_MASTER - Open pseudo-device as the server process
  160.  *    FS_NAMED_PIPE_OPEN - Open a named pipe
  161.  *    FS_CLOSE_ON_EXEC - Cause stream to be closed when the opening
  162.  *        process executes a different program.
  163.  *
  164.  *    (These I/O related bit values are defined in user/fs.h)
  165.  *    FS_READ - Open for reading    (also FS_READABLE)
  166.  *    FS_WRITE - Open for writing    (also FS_WRITABLE)
  167.  *    FS_EXECUTE - Open for execution    (also FS_EXCEPTION)
  168.  *    FS_APPEND - Open for append mode
  169.  *    FS_NON_BLOCKING - Open a stream with non-blocking I/O operations. If
  170.  *        the operation would normally block, FS_WOULD_BLOCK is returned.
  171.  *
  172.  *    (These open-time bit values are defined below)
  173.  *      FS_FOLLOW - follow symbolic links during look up.
  174.  *    FS_PREFIX - Set when opening prefixes for export.
  175.  *    FS_SWAP - Set when opening swap files.  They are not cached on
  176.  *        remote clients and this flag is used to set caching state.
  177.  *    FS_OWNERSHIP - ownership permission.  The calling process has to
  178.  *        own the file in order for a lookup to succeed.  This is
  179.  *        used for setting attributes.
  180.  *    FS_DELETE - Open a file for deletion.  Write permission is needed
  181.  *        in the parent directory for this to succeed.
  182.  *    FS_LINK - This is used by FsLocalLookup to make hard links.  Instead
  183.  *        of creating a new file, FsLocalLookup makes another directory
  184.  *        reference (hard link) to an existing file.
  185.  *    FS_RENAME - This goes with FS_LINK if the link is being made in
  186.  *        preparation for a rename operation.  This allows the link,
  187.  *        which in this case is temporary, to be made to a directory.
  188.  *
  189.  *    (These I/O related bit values are defined below)
  190.  *      FS_USER - the file is a user file.  The buffer space is
  191.  *              in a user's address space.
  192.  *    FS_CLIENT_CACHE_WRITE -    This write is coming from a client's cache.
  193.  *              This means the modify time should not be updated
  194.  *              since the client has the correct modify time.
  195.  *    FS_CONSUME - This is a consuming read from a named pipe.  This is
  196.  *        usually the case for named pipes, although when the ioServer
  197.  *        is writing back blocks from its cache to the file server
  198.  *        this flag is not set.
  199.  *    FS_TRACE_FLAG - This is used to enable the taking of trace records
  200.  *        by low level routines.  This means that the tracing can
  201.  *        be confined to particular operations, like open, while
  202.  *        other operations, like remove, don't pollute the trace.
  203.  *    FS_SIGNAL_REPLY - Valid in Fs_IOReply flags, which shares its
  204.  *        definitions with stream flags.  This flag indicates the
  205.  *        I/O operation is generating a signal.
  206.  *    FS_SERVER_WRITE_THRU - Set on writes that are supposed to be written
  207.  *                   through to the server.
  208.  *    FS_LAST_DIRTY_BLOCK - Set on remote writes when this is the
  209.  *        last dirty block of the file to be written back.
  210.  *    FS_RMT_SHARED - Set on streams that are shared among clients on
  211.  *        separate machines.  For regular files this means that the
  212.  *        stream offset is being maintained on the server.
  213.  *    FS_NEW_STREAM - Migration related.  This tells the I/O server that
  214.  *        the destination of a migration is getting a stream for
  215.  *        the first time.   It needs to know this in order to do
  216.  *        I/O client book-keeping correctly.
  217.  *    FS_WB_ON_LDB - Write this file back to disk if this is the last dirty
  218.  *               block.
  219.  */
  220. #define FS_KERNEL_FLAGS        0xfffff000
  221. #define FS_FOLLOW        0x00001000
  222. #define FS_PREFIX        0x00002000
  223. #define FS_SWAP            0x00004000
  224. #define FS_USER            0x00008000
  225. #define FS_OWNERSHIP        0x00010000
  226. #define FS_DELETE        0x00020000
  227. #define FS_LINK            0x00040000
  228. #define FS_RENAME        0x00080000
  229. #define FS_CLIENT_CACHE_WRITE    0x00100000
  230. #define FS_CONSUME        0x00200000
  231. #define FS_TRACE_FLAG        0x00400000
  232. #define FS_SIGNAL_REPLY        0x00800000
  233. #define    FS_SERVER_WRITE_THRU    0x01000000
  234. #define    FS_LAST_DIRTY_BLOCK    0x02000000
  235. #define FS_RMT_SHARED        0x04000000
  236. #define FS_NEW_STREAM        0x08000000
  237. #define    FS_WB_ON_LDB        0x10000000
  238.  
  239.  
  240. /*
  241.  * Fragment stuff that is dependent on the filesystem block size
  242.  * defined in user/fs.h.  Actually, the fragmenting code is specific
  243.  * to a 4K block size and a 1K fragment size.
  244.  */
  245.  
  246. #define    FS_BLOCK_OFFSET_MASK    (FS_BLOCK_SIZE - 1)
  247. #define    FS_FRAGMENT_SIZE    1024
  248. #define    FS_FRAGMENTS_PER_BLOCK    4
  249.  
  250. /*
  251.  * FS_MAX_LINKS    - the limit on the number of symbolic links that can be
  252.  *    expanded within a single domain.  This is also the limit on the
  253.  *    number of re-directs between domains that can occur during lookup.
  254.  */
  255. #define FS_MAX_LINKS    10
  256.  
  257. /*
  258.  * Values for  page type for Fs_PageRead.
  259.  */
  260. typedef enum {
  261.     FS_CODE_PAGE,
  262.     FS_HEAP_PAGE,
  263.     FS_SWAP_PAGE
  264. } Fs_PageType;
  265.  
  266. /*
  267.  * Buffer type that includes size, location, and kernel space flag.
  268.  * This is passed into Fs_IOControl to specify the input/output buffers.
  269.  */
  270. typedef struct Fs_Buffer {
  271.     Address addr;
  272.     int size;
  273.     int flags;        /* 0 or FS_USER */
  274. } Fs_Buffer;
  275.  
  276. /*
  277.  * Device drivers use Fs_NotifyReader and Fs_NotifyWriter to indicate
  278.  * that a device is ready.  They pass a Fs_NotifyToken as an argument
  279.  * that represents to the file system the object that is ready.
  280.  */
  281. typedef Address Fs_NotifyToken;
  282.  
  283. /*
  284.  * Filesystem initialization calls.
  285.  */
  286. extern    void    Fs_Init();
  287. extern    void    Fs_ProcInit();
  288. extern    void    Fs_SetupStream();
  289. extern    void    Fs_InheritState();
  290. extern    void    Fs_CloseState();
  291.  
  292. /*
  293.  * Prefix Table routines.
  294.  */
  295. extern    void    Fs_PrefixLoad();
  296. extern    void    Fs_PrefixExport();
  297.  
  298. /*
  299.  * Filesystem processes.
  300.  */
  301.  
  302. extern    void    Fs_SyncProc();
  303. extern    void    Fs_Sync();
  304. extern    void    Fs_BlockCleaner();
  305. extern    void    Fs_ConsistProc();
  306. /*
  307.  * Filesystem system calls.
  308.  */
  309. extern    ReturnStatus    Fs_AttachDiskStub();
  310. extern    ReturnStatus    Fs_ChangeDirStub();
  311. extern    ReturnStatus    Fs_CommandStub();
  312. extern    ReturnStatus    Fs_CreatePipeStub();
  313. extern    ReturnStatus    Fs_GetAttributesIDStub();
  314. extern    ReturnStatus    Fs_GetAttributesStub();
  315. extern    ReturnStatus    Fs_GetNewIDStub();
  316. extern    ReturnStatus    Fs_HardLinkStub();
  317. extern    ReturnStatus    Fs_IOControlStub();
  318. extern    ReturnStatus    Fs_LockStub();
  319. extern    ReturnStatus    Fs_MakeDeviceStub();
  320. extern    ReturnStatus    Fs_MakeDirStub();
  321. extern    ReturnStatus    Fs_OpenStub();
  322. extern    ReturnStatus    Fs_ReadLinkStub();
  323. extern    ReturnStatus    Fs_ReadStub();
  324. extern    ReturnStatus    Fs_ReadVectorStub();
  325. extern    ReturnStatus    Fs_RemoveDirStub();
  326. extern    ReturnStatus    Fs_RemoveStub();
  327. extern    ReturnStatus    Fs_RenameStub();
  328. extern    ReturnStatus    Fs_SelectStub();
  329. extern    ReturnStatus    Fs_SetAttributesIDStub();
  330. extern    ReturnStatus    Fs_SetAttributesStub();
  331. extern    ReturnStatus    Fs_SetAttrIDStub();
  332. extern    ReturnStatus    Fs_SetAttrStub();
  333. extern    ReturnStatus    Fs_SetDefPermStub();
  334. extern    ReturnStatus    Fs_SymLinkStub();
  335. extern    ReturnStatus    Fs_TruncateIDStub();
  336. extern    ReturnStatus    Fs_TruncateStub();
  337. extern    ReturnStatus    Fs_WriteStub();
  338. extern    ReturnStatus    Fs_WriteVectorStub();
  339. extern    ReturnStatus    Fs_FileWriteBackStub();
  340.  
  341. /*
  342.  * Filesystem system calls given accessible arguments.
  343.  */
  344. extern    ReturnStatus    Fs_UserClose();
  345. extern    ReturnStatus    Fs_UserRead();
  346. extern    ReturnStatus    Fs_UserReadVector();
  347. extern    ReturnStatus    Fs_UserWrite();
  348. extern    ReturnStatus    Fs_UserWriteVector();
  349.  
  350. /*
  351.  * Kernel equivalents of the filesystem system calls.
  352.  */
  353. extern    ReturnStatus    Fs_ChangeDir();
  354. extern    ReturnStatus    Fs_Close();
  355. extern    ReturnStatus    Fs_Command();
  356. extern    ReturnStatus    Fs_CreatePipe();
  357. extern    ReturnStatus    Fs_CheckAccess();
  358. extern    ReturnStatus    Fs_GetAttributes();
  359. extern    ReturnStatus    Fs_GetAttributesID();
  360. extern    ReturnStatus    Fs_GetNewID();
  361. extern    ReturnStatus    Fs_HardLink();
  362. extern    ReturnStatus    Fs_IOControl();
  363. extern    ReturnStatus    Fs_Lock();
  364. extern    ReturnStatus    Fs_MakeDevice();
  365. extern    ReturnStatus    Fs_MakeDir();
  366. extern    ReturnStatus    Fs_Open();
  367. extern    ReturnStatus    Fs_Read();
  368. extern    ReturnStatus    Fs_ReadLink();
  369. extern    ReturnStatus    Fs_Remove();
  370. extern    ReturnStatus    Fs_RemoveDir();
  371. extern    ReturnStatus    Fs_Rename();
  372. extern    ReturnStatus    Fs_SetAttributes();
  373. extern    ReturnStatus    Fs_SetAttributesID();
  374. extern    ReturnStatus    Fs_SetDefPerm();
  375. extern    ReturnStatus    Fs_SymLink();
  376. extern    ReturnStatus    Fs_Trunc();
  377. extern    ReturnStatus    Fs_TruncFile();
  378. extern    ReturnStatus    Fs_TruncID();
  379. extern    ReturnStatus    Fs_Write();
  380.  
  381. /*
  382.  * Filesystem utility routines.
  383.  */
  384. extern    Boolean        Fs_SameFile();
  385. extern    int        Fs_Cat();
  386. extern    int        Fs_Copy();
  387. extern    void        Fs_HandleScavenge();
  388. extern    void        Fs_PrintTrace();
  389. extern  void        Fs_BlocksToDiskAddr();
  390. extern  void        Fs_CheckSetID();
  391. extern  void        Fs_CloseOnExec();
  392. extern    char *        Fs_GetFileName();
  393.  
  394. /*
  395.  * Routines called via the L1 key bindings.
  396.  */
  397. extern    void        Fs_HandleScavengeStub();
  398. extern    void        Fs_PdevPrintTrace();
  399. extern    void        Fs_DumpCacheStats();
  400. extern    void        Fs_NameHashStats();
  401.  
  402. /*
  403.  * Routines to support process migration: encapsulate and deencapsulate
  404.  * streams and other file state, and clear file state after migration.
  405.  */
  406. extern    ReturnStatus    Fs_EncapStream();
  407. extern    ReturnStatus    Fs_DeencapStream();
  408. extern    int        Fs_GetEncapSize();
  409. extern    ReturnStatus    Fs_InitiateMigration();
  410. extern    void        Fs_StreamCopy();
  411. extern  ReturnStatus    Fs_EncapFileState();
  412. extern  ReturnStatus    Fs_DeencapFileState();
  413.  
  414. /*
  415.  * Routines to wakeup readers and writers.
  416.  */
  417. extern    void        Fs_NotifyReader();
  418. extern    void        Fs_NotifyWriter();
  419. extern    void        Fs_WakeupProc();
  420.  
  421. /*
  422.  * Routines for virtual memory.
  423.  */
  424. extern    ReturnStatus    Fs_PageRead();
  425. extern    ReturnStatus    Fs_PageWrite();
  426. extern    ReturnStatus    Fs_PageCopy();
  427. extern    void        Fs_CacheBlocksUnneeded();
  428. extern    void        Fs_GetPageFromFS();
  429. extern    ClientData    Fs_GetFileHandle();
  430. extern struct Vm_Segment **Fs_GetSegPtr();
  431.  
  432. #endif /* _FS */
  433.